package com.web.app.config;

import com.web.app.util.TokenUtil;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author JMLF
 * @date 2022-10-09
 */
@Component
public class MyInterceptor implements HandlerInterceptor {

    public boolean preHandle(
            HttpServletRequest request,
            HttpServletResponse response,
            Object handler) throws Exception {

        //获取用户传递的token
        //判断token token存在 且未过期
        String token = request.getHeader("Authorization");
        System.err.println("进入拦截器：token--："+token);
//        if(token == null){
//            return true;
//        }
        try {
            String username = TokenUtil.getItem(token, "username");
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }
}
















